package com.jqkb.pages;

import android.app.DownloadManager;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.content.FileProvider;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.webkit.MimeTypeMap;
import android.widget.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.jqkb.DownloadView;
import com.jqkb.R;
import com.jqkb.TheApplication;
import com.jqkb.adapters.ActionForwardAdapter;
import com.jqkb.adapters.HistoryAdapter;
import com.jqkb.service.ActionService;
import com.jqkb.service.bean.ForwardBean;
import com.jqkb.service.bean.User;
import com.jqkb.service.util.CallBack;
import com.jqkb.service.util.Converter;
import com.jqkb.service.util.SimpleApi;
import com.jqkb.utils.Constant;
import okhttp3.ResponseBody;
import org.apache.commons.lang3.StringUtils;
import retrofit2.Call;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ForwardDetailActivity extends AppCompatActivity implements View.OnClickListener {


    private RecyclerView infosRecycleView;
    private RecyclerView historyRecycleView;
    private Button btnShangbao;
    private Button btnPifu;
    private Button btnGuidang;
    private TextView tvShowTitle;
    private TextView tv_show_id;
    private TextView tv_show_type;
    private TextView tv_show_send_user;
    private TextView tv_show_create_time;
    private TextView tv_show_address;
    private TextView tv_show_content;
    private EditText edt_Content;
    private JsonNode forwardPage;
    private JsonNode actionForward;
    private ProgressBar progressBar;
    private NestedScrollView scrollView;
    private ActionForwardAdapter actionForwardAdapter;
    private JsonNode dataPath;
    private LinearLayout filesContainer;
    private String actionSn;
    private LinearLayout footer_container;

    private static Map<String, DownloadEntry> downloadEntryMap = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content);

        btnShangbao = (Button) findViewById(R.id.btnShangbao);
        btnPifu = (Button) findViewById(R.id.btnPifu);
        btnGuidang = (Button) findViewById(R.id.btnGuidang);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        scrollView = (NestedScrollView) findViewById(R.id.scrollView);

        tvShowTitle = (TextView) findViewById(R.id.tv_show_title);
        tv_show_id = (TextView) findViewById(R.id.tv_show_id);
        tv_show_type = (TextView) findViewById(R.id.tv_show_type);
        tv_show_send_user = (TextView) findViewById(R.id.tv_show_send_user);
        tv_show_create_time = (TextView) findViewById(R.id.tv_show_create_time);
        tv_show_address = (TextView) findViewById(R.id.tv_show_address);
        tv_show_content = (TextView) findViewById(R.id.tv_show_content);

        footer_container = (LinearLayout) findViewById(R.id.footer_container);

        edt_Content = (EditText) findViewById(R.id.edt_Content);

        infosRecycleView = (RecyclerView) findViewById(R.id.infosListView);
        historyRecycleView = (RecyclerView) findViewById(R.id.historyListView);
        filesContainer = (LinearLayout) findViewById(R.id.filesContainer);


        btnShangbao.setOnClickListener(this);
        btnPifu.setOnClickListener(this);
        btnGuidang.setOnClickListener(this);
        Intent intent = getIntent();
        Long actionId = intent.getLongExtra(Constant.ACTION_ID, 0);
        Long forwardId = intent.getLongExtra(Constant.FORWARD_ID, 0);
        loadData(actionId == 0 ? null : actionId, forwardId == 0 ? null : forwardId);


        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(intent.getIntExtra(Constant.NOTIFICATION_COUNT, 0));


        User user = TheApplication.getCurrentUser();
        if (!user.hasPermission("BackwardAction")) {
            btnPifu.setVisibility(View.GONE);
        }
        if (!user.hasPermission("ForwardAction")) {
            btnShangbao.setVisibility(View.GONE);
        }


    }


    public void loadData(Long actionId, Long forwardId) {
        scrollView.setScrollY(0);
        footer_container.setVisibility(View.GONE);
        progressBar.setVisibility(View.VISIBLE);

        ActionService service = SimpleApi.create(ActionService.class);
        Call<ResponseBody> responseBodyCall = service.actionForwardDetail(actionId, forwardId);

        Converter.convert(Object.class, responseBodyCall, new CallBack<Object>() {
            @Override
            public void onSuccess(Object object, JsonNode data) {
                progressBar.setVisibility(View.GONE);
                scrollView.setVisibility(View.VISIBLE);
                dataPath = data.path("data");
                JsonNode actionPath = dataPath.path("action");
                actionSn = actionPath.path("sn").asText();
                String title = actionPath.path("title").asText("");
                String sn = actionPath.path("sn").asText("");
                String type = actionPath.path("type").asText("");
                String time = actionPath.path("time").asText("");
                String content = actionPath.path("content").asText("");
                String location = actionPath.path("location").asText("");
                String name = actionPath.path("createdUser").path("name").asText("");
                tv_show_send_user.setText(name);


                tvShowTitle.setText(title);
                tv_show_id.setText(sn);
                tv_show_create_time.setText(time);
                tv_show_address.setText(title);
                tv_show_address.setText(location);
                tv_show_type.setText(type);
                tv_show_content.setText(content);
                tv_show_content.setText(content);

                //批复按钮是否显示

                if (dataPath.path("actionForward").path("targetUser").path("id").asLong() == TheApplication.getCurrentUser().getId() &&
                        dataPath.path("actionForward").path("status").asInt() == 0 &&
                        TheApplication.getCurrentUser().hasPermission("BackwardAction")
                        ) {
                    btnPifu.setVisibility(View.VISIBLE);
                } else {
                    btnPifu.setVisibility(View.GONE);
                }
                //上报按钮是否显示
                if (TheApplication.getCurrentUser().hasPermission("ForwardAction")) {
                    btnShangbao.setVisibility(View.VISIBLE);
                } else {
                    btnShangbao.setVisibility(View.GONE);
                }

                footer_container.setVisibility(View.VISIBLE);

                filesContainer.removeAllViews();
                JsonNode files = actionPath.path("files");
                for (int i = 0; i < files.size(); i++) {
                    String fileName = files.get(i).asText();
                    if (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg") || fileName.endsWith(".gif")) {
                        createFileTypeIcon(R.mipmap.jpg, files.path(i).asText());
                    } else if (fileName.endsWith(".mp3") || fileName.endsWith(".arm") || fileName.endsWith(".acc") || fileName.endsWith(".ogg")) {
                        createFileTypeIcon(R.mipmap.audio, files.path(i).asText());
                    } else if (fileName.endsWith(".mp4") || fileName.endsWith(".mov")) {
                        createFileTypeIcon(R.mipmap.mpg, files.path(i).asText());
                    } else if (fileName.endsWith(".pdf")) {
                        createFileTypeIcon(R.mipmap.pdf, files.path(i).asText());
                    } else if (fileName.endsWith(".doc") || fileName.endsWith(".docx") || fileName.endsWith(".ppt") ||
                            fileName.endsWith(".pptx") || fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                        createFileTypeIcon(R.mipmap.office, files.path(i).asText());
                    } else {
                        createFileTypeIcon(R.mipmap.other, files.path(i).asText());
                    }
                }

                updateDownloadStatus();

                /*
                 * histroy
                 * */

                JsonNode historyList = dataPath.path("historyList");
                HistoryAdapter adapter = new HistoryAdapter(ForwardDetailActivity.this, historyList);
                historyRecycleView.setAdapter(adapter);
                makeRecycleView(historyRecycleView);

                /*
                 * forward
                 * */

                User user = TheApplication.getCurrentUser();

                forwardPage = dataPath.path("forwardPage");
                actionForward = dataPath.path("actionForward");
                JsonNode forwardList = forwardPage;
                JsonNode contentBean = forwardList.path("content");
                List<ForwardBean> beanList = new ArrayList<ForwardBean>();

                int count = 0;
                for (int i = 0; i < contentBean.size(); i++) {
                    ForwardBean forwardBean = new ForwardBean();
                    JsonNode contentNode = contentBean.get(i);
                    forwardBean.setId(contentNode.path("id").asLong());
                    forwardBean.setCreateDate(contentNode.path("action").path("createdDate").asText());
                    forwardBean.setSendUserName(contentNode.path("sendUser").path("name").asText());
                    forwardBean.setTargetUserName(contentNode.path("targetUser").path("name").asText());

                    if (user.getId() == contentNode.path("sendUser").path("id").asLong()) {
                        forwardBean.setVisible(false);
                    } else if (user.getId() == contentNode.path("targetUser").path("id").asLong() && contentNode.path("status").asInt() == 1) {
                        forwardBean.setVisible(false);
                    } else {
                        forwardBean.setVisible(true);
                        count++;
                    }


                    beanList.add(forwardBean);
                }

                if (count == 0) {
                    //隐藏归档按钮
                    btnGuidang.setVisibility(View.GONE);
                }
                actionForwardAdapter = new ActionForwardAdapter(ForwardDetailActivity.this, beanList);
                actionForwardAdapter.setActivity(ForwardDetailActivity.this);
                actionForwardAdapter.setCurrent(dataPath.path("actionForward"));

                infosRecycleView.setAdapter(actionForwardAdapter);
                makeRecycleView(infosRecycleView);
            }

            @Override
            public void onFail(boolean success, int code, String message, JsonNode data) {

                Toast.makeText(ForwardDetailActivity.this, message, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNetworkFail(Call<ResponseBody> jsonNode) {
                Toast.makeText(ForwardDetailActivity.this, "网路连接失败", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(Call<ResponseBody> response) {

            }
        });


    }

    private void updateDownloadStatus() {
        filesContainer.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    if (isDestroyed()) return;
                }
                if (isFinishing()) return;
                int completedCount = 0;//是否存在未完成
                for (int i = 0; i < filesContainer.getChildCount(); i++) {
                    DownloadView dv = (DownloadView) filesContainer.getChildAt(i);
                    DownloadEntry downloadEntry = downloadEntryMap.get(dv.getUrl());
                    if (downloadEntry != null) {
                        dv.setPresent(downloadEntry.present);
                        if (downloadEntry.present == 100) {
                            completedCount++;
                        }
                    } else {
                        File saveFile = toSaveFile(dv.getUrl());
                        if (saveFile.exists() && saveFile.length() > 0) {
                            dv.setPresent(100);
                            completedCount++;
                        }
                    }
                }
                if (completedCount < filesContainer.getChildCount())
                    updateDownloadStatus();
            }
        }, 100);
    }

    private void createFileTypeIcon(final int iconType, final String filePath) {
        final DownloadView downloadView = new DownloadView(this);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100, 100);
        params.gravity = Gravity.CENTER;
        params.setMargins(5, 5, 5, 5);
        downloadView.setLayoutParams(params);
        downloadView.setIconType(iconType);
        downloadView.setUrl(subPathToUrl(filePath));
        downloadView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DownloadView dv = (DownloadView) v;
                File saveFile = toSaveFile(dv.getUrl());
                if (saveFile.exists()) {
                    showFile(saveFile);
                } else {
                    DownloadEntry downloadEntry = downloadEntryMap.get(dv.getUrl());
                    if (downloadEntry == null)
                        download(dv.getUrl());
                }
            }
        });
        filesContainer.addView(downloadView);
    }

    private String subPathToUrl(String subPath) {
        final String fileServerPath = TheApplication.getServer() + subPath;
        return fileServerPath;
    }

    private File toSaveFile(String subUrl) {
        File directory = new File(Environment.getExternalStoragePublicDirectory("JQKB"), actionSn);
        directory.mkdirs();
        return new File(directory, StringUtils.substringAfterLast(subUrl, "/"));
    }


    private void showFile(File file) {
        String fileName = file.getName();
        if (fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".jpeg") || fileName.endsWith(".gif")) {
            Intent intent = getImageFileIntent(file);
            startActivity(intent);
        } else if (fileName.endsWith(".mp3") || fileName.endsWith(".arm") || fileName.endsWith(".acc") || fileName.endsWith(".ogg")) {
            startActivity(getAudioFileIntent(file));

        } else if (fileName.endsWith(".doc") || fileName.endsWith(".docx") || fileName.endsWith(".ppt") ||
                fileName.endsWith(".pptx") || fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
            try {
                startActivity(getWordFileIntent(file));

            } catch (Exception e) {

            }
        } else if (fileName.endsWith(".mp4") || fileName.endsWith(".mov")) {
            startActivity(getVideoFileIntent(file));
        } else if (fileName.endsWith(".pdf")) {
            startActivity(getPdfFileIntent(file));

        } else {


            try {


                Intent intent = new Intent(Intent.ACTION_VIEW);

                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Uri uri;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    uri = FileProvider.getUriForFile(ForwardDetailActivity.this.getApplicationContext(), "com.jqkb.FileProvider", file);
                    // 给目标应用一个临时授权
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else {
                    uri = Uri.fromFile(file);
                }
                String extensionFromMimeType = MimeTypeMap.getSingleton().getExtensionFromMimeType(StringUtils.substringAfterLast(fileName, "."));
                intent.setDataAndType(uri, extensionFromMimeType);
                startActivity(intent);

            } catch (Exception e) {
                Toast.makeText(ForwardDetailActivity.this, "找不到打开文件", Toast.LENGTH_SHORT).show();
            }

        }
    }


    //android获取一个用于打开图片文件的intent
    public Intent getImageFileIntent(File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = null;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(ForwardDetailActivity.this.getApplicationContext(), "com.jqkb.FileProvider", file);
            // 给目标应用一个临时授权
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            uri = Uri.fromFile(file);
        }
        intent.setDataAndType(uri, "image/*");
        return intent;
    }

    //android获取一个用于打开音频文件的intent
    public Intent getAudioFileIntent(File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("oneshot", 0);
        intent.putExtra("configchange", 0);
        Uri uri;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(ForwardDetailActivity.this.getApplicationContext(), "com.jqkb.FileProvider", file);
            // 给目标应用一个临时授权
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            uri = Uri.fromFile(file);
        }
        intent.setDataAndType(uri, MimeTypeMap.getSingleton().getExtensionFromMimeType(StringUtils.substringAfterLast(file.getName(), ".")));
        return intent;
    }


    public Intent getWordFileIntent(File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = null;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(ForwardDetailActivity.this.getApplicationContext(), "com.jqkb.FileProvider", file);
            // 给目标应用一个临时授权
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            uri = Uri.fromFile(file);
        }
        intent.setDataAndType(uri, "application/msword");
        return intent;
    }

    //android获取一个用于打开视频文件的intent
    public Intent getVideoFileIntent(File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("oneshot", 0);
        intent.putExtra("configchange", 0);
        Uri uri = null;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(ForwardDetailActivity.this.getApplicationContext(), "com.jqkb.FileProvider", file);
            // 给目标应用一个临时授权
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            uri = Uri.fromFile(file);
        }
        intent.setDataAndType(uri, "video/*");
        return intent;
    }

    //android获取一个用于打开PDF文件的intent
    public Intent getPdfFileIntent(File file) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(ForwardDetailActivity.this.getApplicationContext(), "com.jqkb.FileProvider", file);
            // 给目标应用一个临时授权
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            uri = Uri.fromFile(file);
        }
        intent.setDataAndType(uri, "application/pdf");
        return intent;
    }


    //下载具体操作
    private void download(final String downloadUrl) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                FileOutputStream fileOutputStream = null;
                try {
                    URL url = new URL(downloadUrl);
                    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                    final long contentLength = httpURLConnection.getContentLength();

                    byte[] bytes = new byte[1024 * 16];
                    int read;
                    DownloadEntry downloadEntry = downloadEntryMap.get(downloadUrl);
                    if (downloadEntry == null) {
                        downloadEntry = new DownloadEntry();
                        downloadEntry.status = DownloadManager.STATUS_RUNNING;
                        downloadEntry.url = downloadUrl;
                        downloadEntryMap.put(downloadUrl, downloadEntry);
                    }
                    InputStream inputStream = httpURLConnection.getInputStream();
                    File tempFile = toSaveFile(downloadUrl + ".temp");
                    File saveFile = toSaveFile(downloadUrl);
                    fileOutputStream = new FileOutputStream(tempFile);
                    long totalWritten = 0;
                    while ((read = inputStream.read(bytes)) != -1) {
                        fileOutputStream.write(bytes, 0, read);
                        totalWritten += read;
                        downloadEntry.present = (int) (totalWritten * 100 / contentLength);
                    }
                    fileOutputStream.close();
                    inputStream.close();
                    httpURLConnection.disconnect();
                    tempFile.renameTo(saveFile);
                    downloadEntryMap.remove(downloadUrl);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };
        thread.start();
    }


    private void makeRecycleView(RecyclerView recyclerView) {
        recyclerView.setLayoutManager(new LinearLayoutManager(this) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setHasFixedSize(true);
        recyclerView.setFocusable(false);
    }

    @Override
    public void onClick(View v) {
        ActionService service = SimpleApi.create(ActionService.class);
        switch (v.getId()) {

            case R.id.btnShangbao:

                if (edt_Content.getText().toString().trim().length() > 0) {
                    Intent intent = new Intent(this, SelectTargetActivity.class);
                    startActivityForResult(intent, 0);
                } else {
                    Toast.makeText(ForwardDetailActivity.this, "内容不能为空", Toast.LENGTH_SHORT).show();
                }

                break;

            case R.id.btnPifu:


                String fillContent = edt_Content.getText().toString();
                if (fillContent.trim().length() == 0) {
                    Toast.makeText(ForwardDetailActivity.this, "不能为空", Toast.LENGTH_SHORT).show();
                    return;

                }
                long actionForwardId = dataPath.path("actionForward").path("id").asLong();
                Call<ResponseBody> forWardCall = service.actionBackward(null, actionForwardId, fillContent);
                Converter.convert(Object.class, forWardCall, new CallBack<Object>() {
                    @Override
                    public void onSuccess(Object object, JsonNode data) {
                        Toast.makeText(ForwardDetailActivity.this, data.path("message").asText(""), Toast.LENGTH_SHORT).show();
                        btnPifu.setVisibility(View.GONE);
                        edt_Content.setText("");
                    }

                    @Override
                    public void onFail(boolean success, int code, String message, JsonNode data) {

                    }

                    @Override
                    public void onNetworkFail(Call<ResponseBody> jsonNode) {

                    }

                    @Override
                    public void onError(Call<ResponseBody> response) {

                    }
                });
                break;

            case R.id.btnGuidang:


                final List<ForwardBean> checkList = actionForwardAdapter.getCheckList();

                if (checkList.isEmpty()) {
                    Toast.makeText(ForwardDetailActivity.this, "选择对象", Toast.LENGTH_SHORT).show();
                    return;
                }
                for (int i = 0; i < checkList.size(); i++) {
                    final ForwardBean forwardBean = checkList.get(i);
                    Call<ResponseBody> call = service.readForward(forwardBean.getId());
                    final int finalI = i;
                    Converter.convert(Object.class, call, new CallBack<Object>() {
                        @Override
                        public void onSuccess(Object object, JsonNode data) {
                            if (finalI == checkList.size() - 1) {
                                Toast.makeText(ForwardDetailActivity.this, data.path("message").asText(""), Toast.LENGTH_SHORT).show();
                            }
                            forwardBean.setVisible(false);
                            forwardBean.setCheck(false);
                            actionForwardAdapter.notifyDataSetChanged();

                        }

                        @Override
                        public void onFail(boolean success, int code, String message, JsonNode data) {


                        }

                        @Override
                        public void onNetworkFail(Call<ResponseBody> jsonNode) {

                        }

                        @Override
                        public void onError(Call<ResponseBody> response) {

                        }
                    });

                }

                break;
        }

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (data != null) {

            ArrayList<String> ids = data.getStringArrayListExtra("users");
            Long[] targetIds = new Long[ids.size()];
            for (int i = 0; i < ids.size(); i++) {
                String id = ids.get(i);
                targetIds[i] = new Long(id);

            }


            ActionService service = SimpleApi.create(ActionService.class);
            Call<ResponseBody> call = service.actionForward(actionForward.path("id").asLong(), edt_Content.getText().toString(), targetIds);
            Converter.convert(Object.class, call, new CallBack<Object>() {
                @Override
                public void onSuccess(Object object, JsonNode data) {
                    if (data.path("code").asInt() == 2000) {
                        edt_Content.setText("");

                    }
                    Toast.makeText(ForwardDetailActivity.this, data.path("message").asText(), Toast.LENGTH_SHORT).show();


                }

                @Override
                public void onFail(boolean success, int code, String message, JsonNode data) {

                }

                @Override
                public void onNetworkFail(Call<ResponseBody> jsonNode) {

                }

                @Override
                public void onError(Call<ResponseBody> response) {

                }
            });


        }


    }

    @Override
    public void onBackPressed() {
        if (getIntent().getIntExtra(Constant.NOTIFICATION_COUNT, 0) == 0) {
            super.onBackPressed();

        } else {
            finish();
            startActivity(new Intent(this, MainActivity.class));
        }

    }

    public static class DownloadEntry {
        public int present;
        public int status;
        public String url;
    }
}
